#include <iostream>
#include <algorithm>
using namespace std;

const int N = 100010;

struct Range
{
    int l, r;
    // 要按右端点排序
    bool operator<(const Range &W) const {
        return r < W.r;
    }
} range[N];

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) scanf("%d%d", &range[i].l, &range[i].r);

    sort(range, range + n);

    int res = 0, end = -2e9;
    for (int i = 0; i < n; i++)
        // 如果上一次选的区间右端点是小于当前区间左端点，
        // 那么当前区间就必须有个点要选，则选其右端点
        if (end < range[i].l) {
            res++;
            end = range[i].r;
        }

    printf("%d\n", res);
    return 0;
}
